package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.cart.client.CartFeignClient;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Fxz
 * @version 1.0
 * @date 2022-02-16 16:28
 */
@Controller
@RequiredArgsConstructor
public class CartController {

	private final CartFeignClient cartFeignClient;

	private final ProductFeignClient productFeignClient;

	@GetMapping("addCart.html")
	public String addCart(@RequestParam("skuId") Long skuId, @RequestParam("skuNum") Integer skuNum,
			HttpServletRequest request) {
		cartFeignClient.addToCart(skuId, skuNum);
		SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
		request.setAttribute("skuInfo", skuInfo);
		request.setAttribute("skuNum", skuNum);
		return "cart/addCart";
	}

	@GetMapping("cart.html")
	public String cartList() {
		return "cart/index";
	}

}
